<?php if (!empty($carts)): if ($session->read('Auth.User.id') != null): ?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="check-out-table">
            <?php  foreach ($carts as $key => $cartitems): ?>
                <tr><th colspan="2" class="common-title" style="padding:10px 0;">Seller: <a href="<?php echo Configure::read('base_url'); ?>products/store/<?php echo $key; ?>"><?php echo $carts_seller[$key]; ?></a></th></tr>  
                <tr><td valign="top">		
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" id="table_<?php echo $key; ?>">
                            <tr><th width="130" bgcolor="#ccc" align="center">Item</th><th width="65" bgcolor="#ccc" align="center">Sub-Total</th><th width="65" bgcolor="#ccc" align="center">Sales Tax</th><th width="148" bgcolor="#ccc" align="center">Action</th><th width="190" bgcolor="#ccc" align="center">Shipping</th></tr>
                            <?php
                            $vendor_total = 0;
                            $total_tax = 0;
                            $custom = "";
                            $use_google_checkout = "";
                            $use_paypal = "";

                            foreach ($cartitems as $cartitem):
                                
                                $city = $cartitem['User']['City']['name'];
                                $state = $cartitem['User']['State']['name'];
                                $country = $cartitem['User']['Country']['name'];
                                if ($custom == "")
                                    $custom.=$cartitem['Cart']['id'];
                                else
                                    $custom.="|" . $cartitem['Cart']['id'];

                                $shipping_id[$cartitem['Cart']['id']] = $cartitem['Cart']['shipping_id'];
                                $shipping_cost[$cartitem['Cart']['id']] = $cartitem['Cart']['shipping_cost'];
                                if (isset($cartitem['Product']['Category']['shipping_weight']) > 0)
                                    $shipping_weight[$cartitem['Cart']['id']] = $cartitem['Product']['Category']['shipping_weight'];
                                ?>
                                <tr>
                                    <td colspan="5">
                                        <form name="CartUpdatequantityForm_<?php echo $cartitem['Cart']['id']; ?>" id="CartUpdatequantityForm_<?php echo $cartitem['Cart']['id']; ?>" method="post" action="" accept-charset="utf-8">
                                            <div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
                                                <tr rowID="row_<?php echo $cartitem['Cart']['id']; ?>">
                                                    <td class="ta-left" width="130">
                                                        <a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $cartitem['Product']['id']; ?>" target="_blank" title="<?php echo $cartitem['Product']['products_title']; ?>"><?php echo $cartitem['Product']['products_title']; ?></a><br />Price: US $<span id="itemprice_<?php echo $cartitem['Cart']['id']; ?>"><?php echo $cartitem['Cart']['product_cost']; ?></span>
                                                        <p>
                                                            <label>Quantity : </label><input type="text" name="data[Cart][quantity]"  id="quantity_<?php echo $cartitem['Cart']['id']; ?>"  value="<?php echo $cartitem['Cart']['quantity']; ?>" size="5" /><br /><br />
                                                            <input type="submit" class="cartButton update_quantity button" sellerID="<?php echo $cartitem['Product']['user_id']; ?>"  CartID="<?php echo $cartitem['Cart']['id']; ?>" value="Update Quantity" />
                                                            <input type="hidden" value="<?php echo $cartitem['Cart']['id']; ?>" name="data[Cart][cart_id]" />

                                                        </p>
                                                    </td>
                                                    <td width="65">US $<span class="subTotal" id="sub_total_<?php echo $cartitem['Cart']['id']; ?>"><?php echo ($cartitem['Cart']['quantity'] * $cartitem['Cart']['product_cost']); ?></span></td>
                                                    <td width="65">
                                                        <?php
                                                        if ($cartitem['Product']['tax_us'] == "Yes") {
                                                            foreach ($cartitem['Product']['Salestax'] as $salestax) {
                                                                if ($salestax['state_id'] == $session->read('Auth.User.state_id')) {
                                                                    $tax = ($salestax['rate'] * $cartitem['Cart']['product_cost']) / 100;
                                                                    $total_tax = $total_tax + $tax;
                                                                    echo"US $<span class='subTotal' id='SalesTax_" . $cartitem['Cart']['id'] . "'>" . $tax . "</span>
								<input type='hidden' value='" . $tax . "' name='data[Cart][sales_tax]'>";
                                                                }else
                                                                    echo "US $<span>0.00</span>";
                                                            }
                                                        }else {
                                                            echo "US $<span>0.00</span>";
                                                        }
                                                        $vendor_total = $vendor_total + ($cartitem['Cart']['quantity'] * $cartitem['Cart']['product_cost']) + $total_tax;
                                                        ?>				
                                                    </td>    
                                                    <td width="148" style="vertical-align: middle;"><a href="<?php echo Configure::read('base_url'); ?>carts/removecartitem/<?php echo $cartitem['Cart']['id']; ?>" class="removeCart" CartID="<?php echo $cartitem['Cart']['id']; ?>"><img src="<?php echo Configure::read('base_url'); ?>img/remove-btn.gif" width="148" height="20" /></a></td>    
                                                    <td width="190">
                                                        <?php
                                                        $shipping_methods1="";
                                                        if (isset($cartitem['Product']['ProductShipping'])) {
                                                            //domestic Shipping methods
                                                            $i = 0;
                                                            foreach ($cartitem['Product']['ProductShipping'] as $shippings) {
                                                                $shipping_methods1[$i]['id'] = $shippings['Shipping']['id'];
                                                                $shipping_methods1[$i]['method'] = $shippings['Shipping']['shipping_method'];
                                                                $i++;
                                                            }
                                                            //International Shipping methods
                                                            $j = 0;
                                                            foreach ($cartitem['Product']['ProductInternationalShipping'] as $shippings) {
                                                                $shipping_methods2[$i]['id'] = $shippings['Shipping']['id'];
                                                                $shipping_methods2[$i]['method'] = $shippings['Shipping']['shipping_method'];
                                                                $j++;
                                                            }
                                                            if (isset($shipping_methods2))
                                                                $shipping_methods = array_merge($shipping_methods1, $shipping_methods2);
                                                            else
                                                                $shipping_methods = $shipping_methods1;
                                                        }
                                                        ?>
                                                        <select id="shippingmethod_<?php echo $cartitem['Cart']['id']; ?>" name="data[Cart][shipping_method]" onchange="return update_cart(<?php echo $cartitem['Cart']['id']; ?>,this.value)">
                                                            <option value="0">Select a Shipping Method</option>
                                                            <?php
                                                            $selected = "";
                                                            foreach ($shipping_methods as $shipping_method) {
                                                                if ($shipping_method['id'] == $cartitem['Cart']['shipping_id'])
                                                                    $selected = ' selected="selected"';
                                                                else
                                                                    $selected = "";
                                                                ?>
                                                                <option <?php echo $selected; ?> value="<?php echo $shipping_method['id']; ?>"><?php echo $shipping_method['method']; ?></option>
                                                            <?php } ?>
                                                        </select>
                                                        <br>
                                                        <span id="shippingprice_<?php echo $cartitem['Cart']['id']; ?>"><?php echo $cartitem['Shipping']['shipping_method'] . " $" . $cartitem['Cart']['shipping_cost']; ?></span>
                                                        <span class="subTotal" id="shippingpricehidden_<?php echo $cartitem['Cart']['id']; ?>" style="display:none;"><?php echo $cartitem['Cart']['shipping_cost']; ?></span>
                                                    </td> 
                                                </tr> 
                                            </table><?php echo $this->Form->end(); ?>
                                    </td>
                                </tr>

                                <?php
                                if ($cartitem['Product']['use_paypal'] == "Yes")
                                    $use_paypal = "Yes";
                                if ($cartitem['Product']['use_google_checkout'] == "Yes")
                                    $use_google_checkout = "Yes";

                            endforeach;
                            ?>			
                        </table>

                    </td>
                    <td valign="top">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr><th bgcolor="#ccc" valign="top" colspan="2">&nbsp;</th></tr>
                            <tr>
                                <td class="ta-left">
                                    <span style="font-size:14px">Shipping Address</span>(<a href="<?php echo Configure::read('base_url'); ?>users/my_address_book">Change</a>)<br />
                                    <?php $shippings = $this->requestAction('/users/getshipping_address/'); 
                                      //echo count(($shippings['AddressBookField']));
                                    
                                    if (isset($shippings['AddressBookField'])) {                                        
                                        echo $shippings['AddressBookField']['first_name'] . "&nbsp;" . $shippings['AddressBookField']['last_name'] . "<br />" .
                                        $shippings['AddressBookField']['address_line_1'] . "<br />" . $shippings['AddressBookField']['address_line_2'] . "<br />" ;
                                        if($shippings['AddressBookField']['City']['name'])
                                            echo $shippings['AddressBookField']['City']['name'];
                                        if($shippings['AddressBookField']['State']['name'])
                                            echo  ", ".$shippings['AddressBookField']['State']['name'];
                                        if($shippings['AddressBookField']['zip'])
                                            echo ", ".$shippings['AddressBookField']['zip']."<br />";
                                        if($shippings['AddressBookField']['Country']['name'])        
                                            echo $shippings['AddressBookField']['Country']['name'] . "<br />";
                                    } else {                                        
                                        echo $session->read('Auth.User.first_name') . "&nbsp;".$session->read('Auth.User.last_name')."<br />";
                                        echo $session->read('Auth.User.address')." <br />"; 
                                        echo $session->read('Auth.User.address2')."<br />";
                                        echo $city; echo ", ".$state;   
                                        echo $session->read('Auth.User.zip')."<br />";
                                        echo $country;
                                    } ?>
                                </td>
                                <td class="vendor">
                                    <?php
                                    arsort($shipping_cost);
                                    foreach ($shipping_cost as $keys => $val) {
                                        $s_cost = $val;
                                        $s_id = $shipping_id[$keys];
                                        if (isset($shipping_weight) && is_array($shipping_weight)) {
                                            unset($shipping_id[$keys]);
                                            unset($shipping_weight[$keys]);
                                            foreach ($shipping_weight as $s_keys => $weight) {
                                                $s_cost = $s_cost + ($weight * 0.50);
                                            }
                                        }
                                        break;
                                    }
                                    ?>
                                    <form name="CartProcessForm_<?php echo $key; ?>" id="CartProcessForm_<?php echo $key; ?>" method="post" action="<?php echo Configure::read('base_url'); ?>carts/order_process" target="_blank" accept-charset="utf-8">
                                        <div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
                                        <input type="hidden" name="data[shipping_method]" value="<?php $sm = $this->requestAction('/carts/fetch_shipping_method/' . $s_id);
                        echo $sm['Shipping']['shipping_method']; ?>" />
                                        <input type="hidden" name="data[shipping_cost]" id="Scost<?php echo $key; ?>" value="<?php echo $s_cost; ?>"  />
                                        <input type="hidden" name="data[sellerID]" value="<?php echo $key; ?>"  />
                                        <input type="hidden" value="<?php echo $custom; ?>" name="data[custom]" />
                                        <input type="hidden" name="data[vendor_total]" id="vendor_total_<?php echo $key; ?>" value="<?php echo ($vendor_total + $s_cost); ?>"  />
                                        <h2><span style="color:#000;">Total: </span>US $<span id="vendorprice_<?php echo $key; ?>"><?php echo ($vendor_total + $s_cost); ?></span></h2>
                                        <br><span style="color:#000;">With Shipping Cost: </span>US $<span id="s_cost_<?php echo $key; ?>"><?php echo $s_cost; ?></span>
                                        <p>&nbsp;</p>
                                        <p><?php
                                   if ($use_paypal == "Yes"):
                                       echo $this->Form->input("payment", array("div" => false, "label" => false, "type" => "hidden", "value" => "Paypal"));
                                        ?>
                                                <input type="image" name="paypal" form_id="<?php echo $key; ?>" class="processpayment" src="<?php echo Configure::read('base_url'); ?>img/paypal.gif" />
                                            <?php endif; ?>&nbsp;&nbsp;
                                            <?php if ($use_google_checkout == "Yes"): ?>
                                                <input type="image" name="gcheckout" form_id="<?php echo $key; ?>" class="processpayment"  src="<?php echo Configure::read('base_url'); ?>img/google_checkout.gif" />
                                            <?php endif; ?>
                                        </p> 
                                    </form>
                                </td></tr>
                        </table>
                    </td>
                </tr>

            <?php endforeach; ?>
            <tr><td colspan="2"><a href="<?php echo Configure::read('base_url'); ?>" style="text-decoration: none;"><input type="button" value="Continue Shopping" class="button" /></a></td></tr>
        </table>


    <?php else: ?>

        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="check-out-table">
            <?php foreach ($carts as $key => $cartitems): ?>
                <tr><th colspan="2" class="common-title" style="padding:10px 0">Seller: <a href="<?php echo Configure::read('base_url'); ?>products/store/<?php echo $key; ?>"><?php echo $carts_seller[$key]; ?></a></th></tr>  
                <tr><td valign="top">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" id="table_<?php echo $key; ?>">
                                <!--tr><th bgcolor="#ccc">Item</th><th bgcolor="#ccc">Sub-Total</th><th bgcolor="#ccc">Action</th></tr-->
                            <tr><th width="230" bgcolor="#ccc" align="center">Item</th><th width="180" bgcolor="#ccc" align="center">Sub-Total</th><th bgcolor="#ccc" align="center">Action</th></tr>
                            <?php
                            $vendor_total = 0;
                            $total_tax = 0;
                            $custom = "";
                            $use_google_checkout = "";
                            $use_paypal = "";

                            foreach ($cartitems as $cartitem):
                                ?>
                                <tr>
                                    <td colspan="3">
                                        <form name="CartUpdatequantityForm_<?php echo $cartitem['Cart']['id']; ?>" id="CartUpdatequantityForm_<?php echo $cartitem['Cart']['id']; ?>" method="post" action="" accept-charset="utf-8">
                                            <div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
                                            <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
                                                <tr id="row_<?php echo $cartitem['Cart']['id']; ?>">
                                                    <td class="ta-left" width="230">
                                                        <a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $cartitem['Product']['id']; ?>" target="_blank" title="<?php echo $cartitem['Product']['products_title']; ?>"><?php echo $cartitem['Product']['products_title']; ?></a><br />Price: US $<span id="itemprice_<?php echo $cartitem['Cart']['id']; ?>"><?php echo $cartitem['Cart']['product_cost']; ?></span>
                                                        <p>
                                                            <label>Quantity : </label><input type="text" name="data[Cart][quantity]"  id="quantity_<?php echo $cartitem['Cart']['id']; ?>"  value="<?php echo $cartitem['Cart']['quantity']; ?>" size="5" />&nbsp;&nbsp;&nbsp;
                                                            <input type="submit" class="update_quantity button" sellerID="<?php echo $cartitem['Product']['user_id']; ?>"  CartID="<?php echo $cartitem['Cart']['id']; ?>" value="Update Quantity" />
                                                            <input type="hidden" value="<?php echo $cartitem['Cart']['id']; ?>" name="data[Cart][cart_id]" />

                                                        </p>
                                                    </td>
                                                    <td  width="180">US $<span class="subTotal" id="sub_total_<?php echo $cartitem['Cart']['id']; ?>"><?php echo ($cartitem['Cart']['quantity'] * $cartitem['Cart']['product_cost']); ?></span></td>
                                                    <td style="vertical-align: middle;"><a href="<?php echo Configure::read('base_url'); ?>carts/removecartitem/<?php echo $cartitem['Cart']['id']; ?>" class="removeCart" CartID="<?php echo $cartitem['Cart']['id']; ?>"><img src="<?php echo Configure::read('base_url'); ?>img/remove-btn.gif" width="148" height="20" /></a></td> 				 
                                                </tr>
                                            </table><?php echo $this->Form->end(); ?></td></tr>  			
                                <?php
                                if ($cartitem['Product']['use_paypal'] == "Yes")
                                    $use_paypal = "Yes";
                                if ($cartitem['Product']['use_google_checkout'] == "Yes")
                                    $use_google_checkout = "Yes";

                            endforeach;
                            ?>	
                        </table>
                    </td>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr><th bgcolor="#ccc" valign="top">Vendor Total</th></tr>	
                            <tr><td class="vendor">
                                    <h2>US $<span id="vendorprice_<?php echo $key; ?>"><?php echo ($cartitem['Cart']['quantity'] * $cartitem['Cart']['product_cost']); ?></span> <em>*</em></h2>
                                    <p><em>*</em> Without Shipping Cost &amp; Sales Tax</p>
                                    <p><?php if ($use_paypal == "Yes"): ?>
                                            <img src="<?php echo Configure::read('base_url'); ?>img/icon-paypal.gif" width="66" height="24" alt="PAYPAL" />
                                        <?php endif; ?>&nbsp;&nbsp;
                                        <?php if ($use_google_checkout == "Yes"): ?>
                                            <img src="<?php echo Configure::read('base_url'); ?>img/icon-google.gif" width="64" height="24" alt="GOOGLE" />
            <?php endif; ?>
                                    </p>
                                    <p class="btn-checkout"><input type="button" value="Login to Checkout" onclick="showPop(this)" title="login" action="popup_login" controller="users" class="button" /></p>
                                </td></tr>
                        </table>
                    </td>
                </tr>
        <?php endforeach; ?>
            <tr><td colspan="2"><a href="<?php echo Configure::read('base_url'); ?>" style="text-decoration: none;"><input type="button" value="Continue Shopping" class="button" /></a></td></tr> 
        </table>

    <?php endif;
else: ?>
    <br /><br /><br />
    <h2>Your cart is empty. <a href="<?php echo Configure::read('base_url'); ?>" style="text-decoration: none;"><input type="button" value="Continue Shopping" class="button" /></a></h2>

    <br /><br /><br />
<?php endif; ?>